package com.jykj.hqh;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.sdk.xmwebviewsdk.interf.WebviewCallBack;
import com.sdk.xmwebviewsdk.view.XMWebView;

public class CustomerWebViewActivity extends AppCompatActivity {

    private String url;
    private XMWebView xmWebView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.url = this.getIntent().getStringExtra("url");
        setContentView(R.layout.activity_customer_webview);
        // AndroidBug5497Workaround.assistActivity(this);
        // 获取 XMWebView 实例
        xmWebView = findViewById(R.id.webView);
        xmWebView.loadUrl(this.url);

        // 设置窗口高度为半屏
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.height = WindowManager.LayoutParams.MATCH_PARENT / 3 * 2;
        getWindow().setAttributes(params);

        // 设置上半部分透明
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        
        // 设置点击透明部分退出页面
        View transparentView = findViewById(R.id.transparent_view);
        transparentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        Log.i("客服网页", "加载字符串: " + url);
    }

    protected void onDestroy() {
        super.onDestroy();
        if (this.xmWebView != null) {
            this.xmWebView.setWebviewCallback((WebviewCallBack)null);
            this.xmWebView.onDestory();
        }

    }
}